package ${businessPackagePath}.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import ${businessPackagePath}.service.${changeTableName}Service;
import com.gitee.make.money.file.management.utils.CheckUtil;
import ${entityPackagePath}.${changeTableName};
import com.gitee.make.money.file.management.utils.SystemConstant;
import com.gitee.make.money.file.management.utils.Res;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.validation.Valid;

/**
 * @author ${author}
 * @company gitee.com/money-making-team
 * @create ${date}
 */
@RestController
@RequestMapping("/${modelPath}/${changeTableName?uncap_first}")
@Api(value = "${tableAnnotation}-API ")
public class ${changeTableName}Controller {

    @Autowired
    private ${changeTableName}Service ${changeTableName?uncap_first}Service;

    @GetMapping("/get${changeTableName}ListByPage/{pageNum}/{pageSize}")
    @ApiOperation(value = "分页条件查询")
    public Res<IPage<${changeTableName}>> get${changeTableName}ListByPage(@ApiParam(value = "页数",example = "1")@PathVariable("pageNum") int pageNum,@ApiParam(value = "一页大小",example = "10")@PathVariable("pageSize") int pageSize,${changeTableName} ${changeTableName?uncap_first}){
        IPage ${changeTableName?uncap_first}PageList = ${changeTableName?uncap_first}Service.get${changeTableName}ListByPage(pageNum,pageSize,${changeTableName?uncap_first});
        return Res.ok(${changeTableName?uncap_first}PageList);
    }

    @GetMapping("/get${changeTableName}ById/{id}")
    @ApiOperation(value = "根据主键查询")
    public Res<${changeTableName}> get${changeTableName}ById(@ApiParam("主键")@PathVariable("id") String id){
        ${changeTableName} ${changeTableName?uncap_first} = ${changeTableName?uncap_first}Service.get${changeTableName}ById(id);
        return Res.ok(${changeTableName?uncap_first});
    }

    @PostMapping("/insert${changeTableName}")
    @ApiOperation(value = "新增")
    @ApiResponses({
        @ApiResponse(code = SystemConstant.CODE_OK,message = "新增个数")
    })
    public Res<Integer> insert${changeTableName}(@Valid @RequestBody ${changeTableName} ${changeTableName?uncap_first}, BindingResult result){
        CheckUtil.checkValidated(result);
        return Res.ok(${changeTableName?uncap_first}Service.insert${changeTableName}(${changeTableName?uncap_first}));
    }

    @PutMapping("/update${changeTableName}ById/{id}")
    @ApiOperation(value = "根据主键更新数据")
    @ApiResponses({
        @ApiResponse(code = SystemConstant.CODE_OK,message = "修改个数")
    })
    public Res<Integer> update${changeTableName}ById(@ApiParam("主键")@PathVariable("id") String id,@RequestBody ${changeTableName} ${changeTableName?uncap_first}){
        return Res.ok(${changeTableName?uncap_first}Service.update${changeTableName}ById(id,${changeTableName?uncap_first}));
    }

    @DeleteMapping("/delete${changeTableName}ById/{id}")
    @ApiOperation(value = "根据主键删除数据")
    @ApiResponses({
        @ApiResponse(code = SystemConstant.CODE_OK,message = "删除个数")
    })
    public Res<Integer> delete${changeTableName}ById(@ApiParam("主键")@PathVariable("id") String id){
        return Res.ok(${changeTableName?uncap_first}Service.delete${changeTableName}ById(id));
    }
}
